import json

dict1 = {}
# 写入信息到列表中
dict1['name'] = '人工智能中的数学'
dict1['author'] = '汤姆森'
dict1['price'] = 85.5

json_str = json.dumps(dict1)
print(json_str)

# 写入文件
with open('AI.json','w',encoding='utf-8') as f1:
    # 把python对象转为字符串，并写入文件  dump（）方法
    json.dump(dict1,f1)


with open('AI.json','r',encoding='utf-8') as f2:
    # 读取内容转字典并赋值
    py_obs = json.load(f2)
    print(py_obs)